/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-10-19
 * Time: 16:02
 */
public class PhoneCard {
    // 变量
    private String cardNumber;
    private double balance;
    private String password;

    // 构造方法
    public PhoneCard(String cardNumber, double initialBalance, String password) {
        this.cardNumber = cardNumber;
        this.balance = initialBalance;
        this.password = password;
    }

    // 拨号方法
    public void dial(String number, double cost) {
        System.out.println("Dialing number: " + number);
        if (cost <= balance) {
            deduct(cost);
            System.out.println("Call successful.");
        } else {
            System.out.println("Insufficient balance. Call failed.");
        }
    }

    // 扣款方法
    private void deduct(double amount) {
        balance -= amount;
        System.out.println("Deducted: " + amount + ". Remaining balance: " + balance);
    }

    // 查询余额方法
    public double queryBalance() {
        return balance;
    }

    // 获取卡号（用于显示或验证）
    public String getCardNumber() {
        return cardNumber;
    }

    public static void main(String[] args) {
        // 创建PhoneCard对象
        PhoneCard phoneCard = new PhoneCard("1234567890", 100.0, "1234");

        // 查询余额
        System.out.println("Initial balance: " + phoneCard.queryBalance());

        // 拨号并扣款
        phoneCard.dial("123456789", 10.5);
        phoneCard.dial("987654321", 25.0);

        // 再次查询余额
        System.out.println("Remaining balance after calls: " + phoneCard.queryBalance());

        // 显示卡号（实际应用中应避免直接显示卡号，这里仅用于演示）
        System.out.println("Card number: " + phoneCard.getCardNumber());
    }
}
